import request from '@/utils/request'
import Qs from "qs";
import axios from "axios";
export function Mylogin(userNo,password){
    var qs = require("qs");
    return axios
    .create({
      baseURL: process.env.VUE_APP_BASE_API1,
      headers: { "Content-Type": "application/json" },
    })
    .post(
      "/auth/connect/token",
      qs.stringify({
        client_id: "HM.IOT.AuthClient",
        client_secret: "Init900701",
        grant_type: "password",
        username: "PASSWORD::" + userNo.replace(
          /(^\s*)|(\s*$)/g,
          ""
        ),
        password: password.replace(
          /(^\s*)|(\s*$)/g,
          ""
        ),
      }),
      {
        headers: {
          "Content-Type": "application/x-www-form-urlencoded",
        },
      }
    )
}
export function getImgUrl(){
    return request({
        url:`/user/api/User/GetImageCode`,
        method:'get',
    })
}
// 获取短信验证码
export function getCode(mobile,imageCodeGuid,imageCode){
    return request({
        url:`/user/api/User/GetSMSCode?mobile=${mobile}&imageCodeGuid=${imageCodeGuid}&imageCode=${imageCode}`,
        method:'get',
    })
}
// 手机号登录
export function MobileAndSMSCodeLogin(mobile,smsCode){
  var qs = require("qs");
    return axios
    .create({
      baseURL: process.env.VUE_APP_BASE_API1,
      headers: { "Content-Type": "application/json" },
    })
    .post(
      "/auth/connect/token",
      qs.stringify({
        client_id: "HM.IOT.AuthClient",
        client_secret: "Init900701",
        grant_type: "password",
        username: "SMSCODE::" + mobile.replace(
          /(^\s*)|(\s*$)/g,
          ""
        ),
        password: smsCode.replace(
          /(^\s*)|(\s*$)/g,
          ""
        ),
      }),
      {
        headers: {
          "Content-Type": "application/x-www-form-urlencoded",
        },
      }
    )
}

